/*
 * ToolCenterApp.java
 */

package com.piza.toolcenter;

import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class ToolCenterApp extends SingleFrameApplication {


    private static Logger logger=Logger.getLogger(ToolCenterApp.class);

    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        String syspath=System.getProperty("user.dir");
        logger.info("Load System properties from: "+syspath);
        try{
          Properties proFile=new Properties();
          proFile.load(new FileInputStream(syspath+File.separator+"toolcenter.properties"));
          Iterator proIte=proFile.stringPropertyNames().iterator();
          while(proIte.hasNext()){
              String keyStr=proIte.next().toString();
              System.getProperties().setProperty(keyStr, proFile.getProperty(keyStr));
          }
        }catch(Exception e){
            logger.error("Encountered exception when load system properties!");
            e.printStackTrace();
        }

        show(new ToolCenterView(this));
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of ToolCenterApp
     */
    public static ToolCenterApp getApplication() {
        return Application.getInstance(ToolCenterApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(ToolCenterApp.class, args);
    }
}
